class Solution {
public:
    string multiply(string num1, string num2)
    {
        string s(num1.size() + num2.size(), '0');
        int index = 0;
        for(int i = num2.size() - 1; i >= 0; --i) {
            int flag = 0;
            for(int j = num1.size() - 1; j >= 0; --j) {
                int t = (num2[i] - '0') * (num1[j] - '0');
                index = num2.size() - 1 - i + num1.size() - 1 - j;
                int te = (s[index] - '0') + t % 10 + flag;
                s[index] = (te) % 10 + '0';
                flag = t / 10 + (te) / 10;
            }
            s[index + 1] = flag + '0';
        }
        reverse(s.begin(), s.end());
        for(int i = 0; i < s.size(); ++i) {
            if(s[i] != '0') {
                string s1(&s[i]);
                return s1;
            }
        }
        return "0";
    }
};
